module("OOP", package.seeall)

Account = {
    balance = 0,
    withdraw = function (self, v)
        self.balace = self.balance - v
    end
}

function Account:deposit(v)
    self.balance = self.balance + v
end

function Account:new(o)
    o = o or {}
    setmetatable(o, self)
    self.__index = self
    return o
end

a = Account:new({balance = 0})
a:deposit(100.00)

-- 第一次用到b.balance，会把Account.balance赋值给b.balance,后续对b.balance的访问就不会涉及__index元方法了，因为此时b已经有自己的balance字段
b = Account:new()
--print(b.balance)

b:deposit(10)
print(b.balance)
print(Account.balance)
